GLOBAL_appid = "sprited";

var draw = function(){
}

var HTMLPixelInfo = function(mosaic,id){
  if(id==undefined)
    id = "HTMLPixelInfo";
  var selector = Selector(mosaic);
  var htmlelement = document.getElementById(id);
  if(htmlelement == null)
    htmlelement = document.createElement("div");
  document.body.appendChild(htmlelement)

  return {
    click:
    function(xpos,ypos){
      var coords = mosaic.coordsOf(xpos,ypos)
      htmlelement.innerHTML = "("+coords[0]+","+coords[1]+")"; 
      selector.deselectAll();
      selector.select(coords[0],coords[1]);
    }
  }

}
var bmpfonttest = function(font){
  var image = document.getElementById(font);
  var stagingmosaic = Mosaic("hiddencanvas",{tileSize:1});
  var stagingmemtile = MemTile(stagingmosaic,0,0,image.width,image.height)
  var imageloader = ImageLoader(image);
  imageloader.sprayImage(stagingmemtile);
  var mainmosaic = Mosaic("canvases",{tileSize:4});
  var f = Font(stagingmemtile,stagingmosaic);
  var info = HTMLPixelInfo(stagingmemtile);
document.onmousedown = function(e){
 info.click(e.pageX,e.pageY)  
  }
}

//takes a memtile with a font
//of chars in ascii order sprayed in it
//and returns a TileManager of MemTiles
//ready for use on the mosaic specified.

var Font =
  function(){ 
    var stagingdiv = document.createElement("div");
    stagingdiv.id = "fontstaging";
    stagingdiv.style.cssText="display: none;";
    document.body.appendChild(stagingdiv);
    var stagingmosaic = Mosaic("fontstaging");

    return  function(fontid){
      imageloader = ImageLoader(fontid);  
      var tilemanager = TileManager(stagingmosaic,MemTile);
      var image       = document.getElementById(fontid);
      var memtile     =  MemTile(stagingmosaic,0,0,image.width,image.height);
      imageloader.sprayImage(memtile);
     
      var stopcolor = memtile.pixels[0][0]
      var oldi=0;
      var charoffset = 0;
      var maxwidth   = 0;
      for(var i =1;i<memtile.xSize;i++){
        var charname = asciiorder[charoffset];
        if(!compareColors(memtile.pixels[0][i],stopcolor) ){
	  var tile = tilemanager.makeTile(oldi+1,0,i-oldi-1,memtile.ySize,charname);
  	  memtile.sprayImage(tile,oldi+1,0,i-oldi-1,memtile.ySize);
          if(i-oldi>maxwidth)
            maxwidth = i-oldi;
          oldi = i;
          charoffset += 1;
        }
    
      }
      return {
        maxwidth:maxwidth,
        tiles:tilemanager,
        print:
        function(mosaic,string,x0,y0){
          var i =0;
          for(c in string){
            var tile = this.tiles.tileNamed(string[c])
            if(!tile) //character not found!  Just ignore it for now.
              continue;
            this.tiles.tileNamed(string[c]).sprayImage(mosaic,0,0,0,0,i+x0,y0) 
            i += this.maxwidth;
          }
        }
      }
    };
  }();
/*  
var SpriteParse(memtile,mosaic){
  var bgcolor = memtile.pixels[0][0];
  
  while(y < memtile.pixels.length){
  
    while( x < memtile.pixels[0].length){
      if(compareColors(bgcolor,memtile.pixels[y][x])){
        var i;
        var j;
       for(j=y;compareColors(memtile.pixels[
        for(i=x;comparecolors(memtile.pixels[y][i],bgcolor);i++)
          continue;
        
      }
    
    }
   col += 1;
  }    
}


  }  
  return{
  
  }

}
*/


var blobfinder = function(memtile,rect){

}



var conway_neighbors = function(coords,pixels){


}

